package com.example.design.clean_craftsmanship

/**
 * 第二章
 **/

/**
 *@see com.example.myapplication.QueueTest
 **/
class OutOfBounds : RuntimeException()
class MyQueue {

    private var mIsEmpty = true
    private var mInts = mutableListOf<Int>()

    fun push(int: Int) {

        mInts.add(int)
        mIsEmpty = false
    }

    fun isEmpty(): Boolean {
        return mIsEmpty
    }

    fun getTop(): Int {
        if (mIsEmpty) throw OutOfBounds()
        return mInts[0]
    }

    fun pop() {
        if (mIsEmpty) {
            throw OutOfBounds()
        }
        mInts.removeAt(0)
        if (mInts.size == 0) mIsEmpty = true
    }

    fun getSize(): Int {
        return mInts.size
    }

    fun getLast(): Int {
        if (mIsEmpty) throw OutOfBounds()
        return mInts[mInts.lastIndex]
    }
}
